package esmaltes.repository;

import javax.persistence.NoResultException;
//import javax.persistence.Query;

import esmaltes.model.Marca;

public class MarcaRepository extends RepositorioGenerico<Marca, Long> {

	private static final long serialVersionUID = 1L;

	public Marca buscaPorDescricao(String descricao) {
		try {
			return super.getManager().createQuery("from Marca where descricao = :descricao", Marca.class)
					.setParameter("descricao", descricao)
					.getSingleResult();
		} catch (NoResultException e) {
			return null;
		}
		
	}
	
//	public void excluirPorChave(Integer chave) {
//		Integer retorno = 0;
//		if (chave > 0) {
//			getManager().getTransaction().begin();
//			String hqlDelete = "DELETE FROM marca WHEREcd_marca = " + chave;
//			Query nativeQuery = getManager().createNativeQuery(hqlDelete);
//			retorno = nativeQuery.executeUpdate();
//			getManager().getTransaction().commit();
//		} else {
//			System.out.println("Erro no valor: " + chave);
//		}
//	}
	
}
